﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ToggleButtonStyle"
           TargetType="ToggleButton">
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Border x:Name="Border"
                            CornerRadius="2"
                            BorderThickness="1"
                            Background="{StaticResource NormalBrush}"
                            BorderBrush="{StaticResource NormalBorderBrush}">
                        <ContentPresenter Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="true">
                            <Setter TargetName="Border"
                                    Property="Background"
                                    Value="{StaticResource DarkBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed"
                                 Value="true">
                            <Setter TargetName="Border"
                                    Property="Background"
                                    Value="{StaticResource PressedBrush}" />
                            <Setter TargetName="Border"
                                    Property="BorderBrush"
                                    Value="{StaticResource PressedBorderBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="Expander">
        <Setter Property="Padding"
                Value="8" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <DockPanel>
                        <ToggleButton Style="{StaticResource ToggleButtonStyle}"
                                      DockPanel.Dock="Top"
                                      IsChecked="{Binding Path=IsExpanded,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                      HorizontalContentAlignment="Left"
                                      VerticalContentAlignment="Center">
                            <ToggleButton.Content>
                                <StackPanel Orientation="Horizontal">
                                    <Path SnapsToDevicePixels="True"
                                          Name="Arrow"
                                          Margin="8,0,8,0"
                                          Fill="{TemplateBinding Foreground}"
                                          Stroke="{TemplateBinding Foreground}"
                                          StrokeThickness="0.5"
                                          RenderTransformOrigin="0.5,0.5"
                                          HorizontalAlignment="Right"
                                          VerticalAlignment="Center"
                                          Data="M 0 0 L 0 8 L 5 4 Z">
                                        <Path.RenderTransform>
                                            <RotateTransform Angle="0" />
                                        </Path.RenderTransform>
                                    </Path>
                                    <ContentPresenter Name="HeaderContent"
                                                      Margin="4"
                                                      ContentSource="Header" />
                                </StackPanel>
                            </ToggleButton.Content>
                        </ToggleButton>
                        <Border Name="Content"
                                BorderThickness="1,0,1,1"
                                BorderBrush="{StaticResource NormalBorderBrush}"
                                Background="{TemplateBinding Background}"
                                CornerRadius="0,0,1,1"
                                SnapsToDevicePixels="True">
                            <Border.LayoutTransform>
                                <ScaleTransform ScaleY="0" />
                            </Border.LayoutTransform>
                            <ContentPresenter Content="{TemplateBinding Content}"
                                              ToolTipService.IsEnabled="False" />
                        </Border>
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Expander.IsExpanded"
                                 Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="LayoutTransform.ScaleY"
                                                         To="1"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Arrow"
                                                         Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)"
                                                         Duration="0:0:0.2"
                                                         To="90"
                                                         DecelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="LayoutTransform.ScaleY"
                                                         To="0"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0"
                                                         Duration="0:0:0.5" />
                                        <DoubleAnimation Storyboard.TargetName="Arrow"
                                                         Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(RotateTransform.Angle)"
                                                         Duration="0:0:0.2"
                                                         AccelerationRatio="1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>